#include "apue.h"
#include <time.h>

#define CMD "/bin/cmdnotexist >/dev/null 2>&1"

void sig_pipe(int signo) {
    printf("sig_pip fire");
    _exit(0);
}

int main(void) {
    int stat, n;
    FILE *fp;
    char str[6];

    if ((fp= popen(CMD, "r")) == NULL)
        err_sys("fopen error");

    if ((n= fread(str, 1, 6, fp)) == 0) {
        if (feof(fp) != 0)
            printf("fread end(EOF)\n");
        else 
            printf("fread receive 0 bytes");
    }
    else
        printf("read %d bytes: %s\n", n, str);

    if ((stat= pclose(fp)) < 0)
        err_sys("pclose error");

    pr_exit(stat);

    return 0;
}

